cmake_minimum_required(VERSION 2.8.0)
project(h2o_app)
find_library(H2O_LIB h2o-evloop)
#find_library(MUSTACHE_C_LIB mustache_c)
find_library(YAJL_LIB yajl)
find_library(FFEAD_LIB ffead-framework)
find_path(H2O_INCLUDE h2o.h)
#find_path(MUSTACHE_C_INCLUDE mustache.h)
find_path(YAJL_INCLUDE yajl/yajl_gen.h)
set(COMMON_OPTIONS -flto -pthread)
add_compile_options(-std=gnu11 -pedantic -Wall -Wextra ${COMMON_OPTIONS})
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_FORTIFY_SOURCE=2")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -O3")
add_definitions(-DH2O_USE_LIBUV=0)
if(OPENSSL_ROOT_DIR)
	include_directories(src ${H2O_INCLUDE} ${YAJL_INCLUDE} ${OPENSSL_ROOT_DIR}/include)
	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${OPENSSL_ROOT_DIR}/lib")
else()
	include_directories(src ${H2O_INCLUDE} ${YAJL_INCLUDE})
endif()
file(GLOB_RECURSE SOURCES "src/*.c")
add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} ${COMMON_OPTIONS})
target_link_libraries(${PROJECT_NAME} ${H2O_LIB} ssl crypto numa pq z ${YAJL_LIB} ${FFEAD_LIB})
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
#file(GLOB TEMPLATES "template/*")
#install(FILES DESTINATION share/${PROJECT_NAME}/template)
